package com.kancy.jemeter.functions;

import com.kancy.jemeter.util.MessageUtil;
import com.kancy.jemeter.util.RandomUtil;
import org.apache.jmeter.functions.InvalidVariableException;
import org.apache.jmeter.samplers.SampleResult;
import org.apache.jmeter.samplers.Sampler;

import java.util.Arrays;
import java.util.LinkedList;
import java.util.List;

/**
 * 手机号码
 */
public class MobileFunction extends JemeterAbstractFunction {

    private static final List<String> towNumberList = Arrays.asList("3","5","6","7","8");


    public MobileFunction() {
        super(0,1);
    }

    @Override
    public String execute(SampleResult sampleResult, Sampler sampler) throws InvalidVariableException {
        StringBuilder sb = new StringBuilder();
        sb.append("1").append(towNumberList.get(RandomUtil.nextInt(towNumberList.size())))
                .append(RandomUtil.nextLong(100000000,999999999));
        return setJMeterVariable(1, sb.toString());
    }

    private static final List<String> argumentDesclist = new LinkedList();

    static {
        argumentDesclist.add(MessageUtil.getResString("varname.message"));
    }
    @Override
    public List<String> getArgumentDesc() {
        return argumentDesclist;
    }
}
